package service.impl.v2;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.v2.MemberTicketVOMapper;
import model.MemberTicketVO;
import service.v2.MemberTicketService;
@Service
public class MemberTicketServiceImpl implements MemberTicketService {
	@Autowired
	private MemberTicketVOMapper dao;

	public int getTotalTicket(String member_id) {
		return dao. getTotalTicket( member_id) ;
	}

	public int selectUseTickets(String member_id) {
		return dao.selectUseTickets(member_id);
	}

	public List<MemberTicketVO> selectTicketKind(String member_id) {
		return dao.selectTicketKind(member_id);
	}

	public int selectDisabledTickets(String member_id) {
		return dao.selectDisabledTickets(member_id);
	}

	public String selectTicketsT(String member_id) {
		return dao.selectTicketsT(member_id);
	}

	public List<MemberTicketVO> selectTicketsDisabledInfo(String member_id,String lang) {
		
		List<MemberTicketVO> tickets_disabledInfo = dao.selectTicketsDisabledInfo(member_id);
		String expire_time = "";
		int day=0;
		int hour=0;
		int minute=0;
		
		for(int i=0;i<tickets_disabledInfo.size(); i++){
			expire_time=tickets_disabledInfo.get(i).getExpire_time();
			int seconds=Integer.parseInt(expire_time);//60*60*24*2+3600*4+180+58;
			if(seconds/(60*60*24)>0){
				 day=seconds/(60*60*24);//换成天
				 hour=(seconds-(60*60*24*day))/3600;//总秒数-换算成天的秒数=剩余的秒数    剩余的秒数换算为小时
				 minute=(seconds-60*60*24*day-3600*hour)/60;//总秒数-换算成天的秒数-换算成小时的秒数=剩余的秒数    剩余的秒数换算为分
				 if(lang==null){
					 tickets_disabledInfo.get(i).setExpire_time("剩余"+day+"天"+hour+"时"+minute+"分钟");
				 }else{
					 tickets_disabledInfo.get(i).setExpire_time(day+"day(s)"+hour+"hour(s)"+minute+"min(s)remaining");
				 }
			}
			if(seconds/(60*60*24)==0 && seconds/3600>0 ){
				 hour=seconds/3600;//
				 minute=(seconds-3600*hour)/60;//总秒数-换算成天的秒数-换算成小时的秒数=剩余的秒数    剩余的秒数换算为分
				 if(lang==null){
					 tickets_disabledInfo.get(i).setExpire_time("剩余"+hour+"时"+minute+"分钟");
				 }else{
					 tickets_disabledInfo.get(i).setExpire_time(hour+"hour(s)"+minute+"min(s)remaining");
				 }
			}
			if(seconds/(60*60*24)==0 && seconds/3600==0 ){
				 minute=seconds/60;//总秒数-换算成天的秒数-换算成小时的秒数=剩余的秒数    剩余的秒数换算为分
				 if(lang==null){
					 tickets_disabledInfo.get(i).setExpire_time("剩余"+minute+"分钟");
				 }else{
					 tickets_disabledInfo.get(i).setExpire_time(minute+"min(s)remaining");
				 }
			}
		}
		
		return tickets_disabledInfo;
	}
}
